<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script src="./js/jquery.min.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/matchzoneview.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/tmatch.js"/></script>



	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>比赛管理</cite></a>
			<a><cite>赛项管理</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid" id="app">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body ">
					<form class="layui-form layui-col-space5 flex" style="display: flex;" @submit.prevent>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛项</div>
							<select  name="projectSelect" lay-filter="projectSelChange" id="saixiang">
								<option value="">请选择</option>
								<option v-for="match in matchList.records" :value="match.id">{{match.theme}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛区</div>
							<select  name="zoneSelect" lay-filter="zoneSelChange" id="saiqu">
								<option value="">请选择</option>
								<option v-for="zone in zoneList" :value="zone.id">{{zone.zoneName}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block">
							<button ref="search" class="layui-btn" lay-submit="" lay-filter="search">
								<i class="layui-icon">&#xe615;</i></button>
						</div>
					</form>
				</div>
				<div id="content" v-cloak>
					<div class="layui-card-header">
						<!--<button class="layui-btn layui-btn-danger" onclick="delAll()">-->
						<!--<i class="layui-icon"></i>批量删除-->
						<!--</button>-->
						<button class="layui-btn" onclick="opend1()">
							<i class="layui-icon"></i>添加赛项
						</button>
					</div>
					<div class="layui-card-body">
						<table class="layui-table layui-form" id="table">
							<span>共计{{ total }}条数据</span>
						</table>
						<section id="page" style="display:none"></section>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script src="./js/vue.js"></script>
<script>
  function opend1(){
		if (localStorage.sysroleId!='1'){
			  alert("不是超级管理员，不能添加赛项！")
				return false
		}
		xadmin.open('添加赛项','project-add.html')
	}
	var app = new Vue({
		el: '#app',
		data: {
			selMatchId:'',
			selZoneId:'',
			creatorList: [],
			gradeList: [],
			matchList: [],
			zoneList: [],
			list: [],
			pageSize: 50,
			pageNo: 1,
			total: 0,
			aaa: 123,
			status: ['审核', '待审核', '通过', '不通过'],
			participate: ['审核', '参赛', '弃权'],
			cols: [ //表头
				{field: 'id', title: '序号'},
				{field: 'theme', title: '赛项名称'},
				{field: 'creatorAccount', title: '创建账号'},
				{field: 'createTime', title: '创建时间'},
				{field: 'operating', title: '操作', width: 135, templet: '#operating'},
			]
		},
		mounted: function () {
			var vm = this
			layui.use('form', function () {
				vm.form = layui.form
				vm.form.on('submit(search)', function (data) {
					var field = data.field
					vm.selMatchId = document.getElementById("saixiang").value
					vm.selZoneId = document.getElementById("saiqu").value

					vm.loadMatchList();
				})
				vm.form.on('select(projectSelChange)', function (data) {
					vm.$refs.search.click()
				})
				vm.form.on('select(zoneSelChange)', function (data) {
					vm.$refs.search.click()
				})
			})
			setTimeout(function () {
				if (vm.form != null) {
					vm.form.render()
				} else {
					layui.use('form', function () {
						layui.form.render()
					})
				}
			}, 1000)
		},
		methods: {
			loadGradeList: function () {
				GradequeryList({}, function (data) {
					app.gradeList = data
				}, function (status, message) {
					alert(message)
				})
			},
			getCreatorAccount: function (varCreatorId) {
				for (var i = 0; i < this.creatorList.length; ++i) {
					if (this.creatorList[i].id == varCreatorId) {
						return this.creatorList[i].userName
					}
				}
			},
			loadMatchList: function () {
				var vm = this
				var queryData = {
					page:{
							current: this.pageNo, //当前页数
							size:this.pageSize   //每页长度
					},

					cond: { //条件
						eq: { // 多条件对象
							id:this.selMatchId==''?null:this.selMatchId,
							zoneId:this.selZoneId==''?null:this.selZoneId
						}

					}
				}
				// alert(JSON.stringify(queryData))
				MatchZoneViewqueryList(queryData, function (data) {
					// alert(JSON.stringify(data))
					app.matchList = data
					var creatorIds = []
					for (var i = 0; i < app.matchList.length; ++i) {
						creatorIds.push(app.matchList[i].createorId)
					}
				 var records=app.matchList
				 var list=[]
				 var list1=[]

				 for (i=0;i<records.length;i++){
					   var string1=list1.toString()
						 if (string1.indexOf(records[i].id)==-1){
							 list1.push(records[i].id)
							 list.push(records[i])
						 }
				 }
				 list=list.reverse()
				 app.matchList.records=list
				//  app.matchList=list
					var cond = {
						in: {
							data: creatorIds,
							attrName: "id"
						}
					}
					AccountqueryList(cond, function (data) {
						app.creatorList = data
						for (var i = 0; i < app.matchList.records.length; ++i) {
							app.matchList.records[i].index = i + (app.matchList.current - 1) * app.matchList.size
							app.matchList.records[i].creatorAccount = app.getCreatorAccount(app.matchList.records[i].createorId)
						}
						app.total = app.matchList.total
						app.list = app.matchList.records
						app.init()
					}, function (status, message) {

					})
				}, function (status, message) {
					// alert(message)
				})
			},
			loadZoneList: function () {
				var funTool = fun_tool();
				app.zoneList=funTool.getAdminZoneIds();
				// ZonequeryList({}, function (data) {
				// 	app.zoneList = data
				// }, function (status, message) {
				// 	alert(message)
				// })
			},
			getData() {
				this.loadGradeList()
				this.loadZoneList()
				this.loadMatchList()
			},
			init: function () {
				var that = this
			  var list=[]
				var idlist=[]
				var id=that.selMatchId
				var zoneId=that.selZoneId



				for (i=0;i<that.list.length;i++){
					 var myid=that.list[i].id
					 myid=myid.toString()
          var myzoneid=that.list[i].zoneId
					myzoneid=myzoneid.toString()
					if (myid.indexOf(id)>-1&&myzoneid.indexOf(zoneId)>-1){
						list.push(that.list[i])
					}

				}
				 that.list=list
				// that.list=that.list.reverse()
				that.total=that.list.length
				layui.use(['laypage', 'table'], function () {
					var table = layui.table
					var laypage = layui.laypage
					table.render({
						elem: '#table',
						url: '',
						title: '用户数据表',
						cols: [that.cols],
						data: that.list,
						limit:50,
						page:true
					})
					that.list = that.list.map(function(item,i){
									if(i<3){
										return item;
									}
								})

								layui.use('laypage', function(){
									var laypage = layui.laypage;
									laypage.render({
										elem:'page',
										count: that.list.length,
										jump:function(obj, first){
											console.log(obj, 1234)
											if(!first){
											that.list = that.list.map(function(item, i){
													if(i < obj.curr * 100){
														return item;
													}
												})
											}
										}
									})
								})

					// laypage.render({
					// 	elem: 'page',
					// 	count: that.total,
					// 	curr: that.pageNo,
					// 	limit: that.pageSize,
					// 	jump: function (obj, first) {
					// 		if (first) return
					// 		that.pageNo = obj.curr
					// 		that.loadMatchList()
					// 	}
					// })
				})
			}
		}
	})
	window.onload = function () {
		app.getData()
	}
	function refresh(){

		app.init()
	}
</script>

<script type="text/html" id="operating">
	<a href="javascript:;" onclick="edit9('{{d.id}}')" class="layui-table-link">编辑</a>
	<a href="saiqu.html?id={{d.id}}" class="layui-table-link">查看</a>
	<a href="javascript:;" class="layui-table-link" onclick="buttonChange('{{d.state}}','{{d.id}}', this)">{{varStateTxt[d.state]}}</a>
</script>

<script>
function edit9(id){
	if (localStorage.sysroleId!='1'){
			alert("不是超级管理员，不能编辑赛项！")
			return false
	}
	 var url1='project-add.html?id='+id
	 xadmin.open('编辑',url1)
}
	var varStateTxt=["发布","关闭","发布"]
	function buttonChange(data,varId, e) {
		if (localStorage.sysroleId!='1'){
			alert("此操作只有管理员才能使用！")
			return false
		}
		// console.log(e.innerText)
		var varStateValue=[1,2,1]
		layer.confirm('确认' + varStateTxt[data] + '吗？',
			function (index) {
				var updateReq={
					id:varId,
					state:varStateValue[data]
				}
				//捉到所有被选中的，发异步进行删除
				e.innerText = varStateTxt[data]

				TmatchupdateById(updateReq,function(data){
						layer.msg('操作成功', {
						icon: 0
					})
					location.reload()
				})

			})
	}

	$(function () {
		layui.use(['form', 'table'], function () {
			var form = layui.form
			// layer.msg('玩命卖萌中', function(){
			//   //关闭后的操作
			//   });
			//监听提交
			// form.on('submit(sreach)', function (data) {
			// 	console.log(data)
			// 	// layer.msg(JSON.stringify(data.field), function () {
			// 	// location.href = 'index.html'
			// 	// })
			// 	return false
			// })
		})
	})
</script>

</html>
